# -*- coding: utf-8 -*-

import cv2 as cv
import numpy as np

haar_cascade = cv.CascadeClassifier("haarcascade_frontalface_default.xml")

people = ["","",""]
# features = np.load("features.npy")
# labels = np.load("labels.npy")

face_recognizer = cv.face.LBPHFaceRecognizer_create()
face_recognizer.read("face_train.yml")

img = cv.imread("")

gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
cv.imshow("Gray", gray)

# Detect the face
face_rect = haar_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighors=3)
for (x,y,w,h) in face_rect:
    face = gray[y:y+h, x:x+w]
    
    label, confidence = face_recognizer.predict(face)
    print(f"Label = {people[label]} with a confidence of {confidence}")
    
    cv.rectangle(img, (x,y), (x+w, y+h), (0,255,0), thickness=2)
    cv.putText(img, str(people[label]), (x,y+h), cv.FONT_HERSHEY_COMPLEX, 1.0, (0,255,0), thickness=2)
    